package com.comet.service;

import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.auto.comet.Socket;
import org.springframework.stereotype.Service;

import com.comet.CometSocketHandler;


@Service
public class CometServiceImpl implements CometService{
	
	//@Autowired
	private CometSocketHandler cometSocketHandler;
	
	public CometSocketHandler getCometSocketHandler() {
		return cometSocketHandler;
	}

	public void setCometSocketHandler(CometSocketHandler cometSocketHandler) {
		this.cometSocketHandler = cometSocketHandler;
	}

	public void sendToAll(String userID,String msg){
		Map<Serializable, Socket> socketMapping = cometSocketHandler.getSocketMapping();
		Set<Serializable> keys = socketMapping.keySet();
		Iterator<Serializable> iterator = keys.iterator();
		while(iterator.hasNext()){
			String key = (String) iterator.next();
			//if(!key.equals(userID)){
				socketMapping.get(key).send(msg);
			//}
		}
	}

}
